<?php
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
if($_RQ['op']=='list'){
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$params=array('uniacid'=>$_SESSION['uniacid']);
    $orderby='id desc';
	$total='';
	$return['list']=pdo_getslice('jy_daibao_yewu',$params,array($pindex,$psize),$total,$fields,'',$orderby);
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$return['isdefault']=array('0'=>'否','1'=>'是');
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'业务列表'),
			array('op'=>'edit','title'=>'添加业务'),
		),
		'list'=>array('data'=>'list','tip'=>'[例如]：企业年报，企业注册，企业注销，异常经营','list'=>array(	
			array('name'=>'paixu','title'=>'排序','type'=>'string'),
			array('name'=>'title','title'=>'业务名称','type'=>'string'),
			array('name'=>'type','title'=>'业务类型','type'=>'radio','options'=>'types'),
			array('name'=>'desc','title'=>'业务介绍','type'=>'string'),
			array('name'=>'image','title'=>'业务图片','type'=>'image'),
			array('name'=>'fee','title'=>'业务价格','type'=>'string'),
			array('name'=>'status','title'=>'是否启用','type'=>'switch','set'=>'set'),				
		)),
	);
	$return['types']=$this->types;
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='edit'){
	$id=intval($_RQ['id']);
	if($id){
		$item=pdo_get('jy_daibao_yewu',array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
	}else{
		$item=array();
	}
    $return['item']=$item;
	$return['status']=array('0'=>'禁用','1'=>'启用');
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'desc'=>'行业设置',
		'tabs'=>array(
			array('op'=>'list','title'=>'返回列表'),
		),
		'edit'=>array(
			array('name'=>'paixu','title'=>'排序','type'=>'string'),
			array('name'=>'title','title'=>'业务名称','type'=>'string'),
			array('name'=>'type','title'=>'业务类型','type'=>'radio','options'=>'types'),
			array('name'=>'desc','title'=>'业务介绍','type'=>'text'),
			array('name'=>'image','title'=>'业务图片','type'=>'image'),
			array('name'=>'fee','title'=>'业务价格','type'=>'string'),
			array('name'=>'images','title'=>'多图','type'=>'images'),
			array('name'=>'content','title'=>'业务详情','type'=>'richtext'),
			array('name'=>'status','title'=>'是否启用','type'=>'switch'),				
		)
	);
	$return['types']=$this->types;
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	$data=array_fields(array('status','title','paixu','desc','image','fee','content','type'),$postdata);
	$data['images']=json_decode($data['images'],true);
	$id=intval($postdata['id']);
	if($id){		
		pdo_update('jy_daibao_yewu',$data,array('id'=>$id));
		exi('设置成功！','','list');
	}else{
		$data['uniacid']=$_SESSION['uniacid'];
		$data['createtime']=time();
		pdo_insert('jy_daibao_yewu',$data);
		exi('添加成功！','','list');
	}
}
if($_RQ['op']=='set'){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先选择要编辑的工种！','error');
	}
	$post=get_postdata();
	if(isset($post['status'])){
		pdo_update('jy_daibao_yewu',array('status'=>intval($post['status'])),array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}
	exi('操作成功！');
}
if($_RQ['op']=='del'){
	$id=intval($_RQ['id']);
	if($id){
		pdo_delete('jy_daibao_yewu',array('id'=>$id));	
	}
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
		foreach($del as $id){
			$id=intval($id);
			if($id){
				pdo_delete('jy_daibao_yewu',array('id'=>$id));
			}
		}
	}
	exi('删除成功！');
}
?>